class Milestone < ActiveRecord::Base
  belongs_to :project
  belongs_to :user
  has_many   :todos
  after_save :save_log
def save_log
  Log.info(self.project,
       "<a href=/projects/#{self.project_id}/milestones>#{self.name}</a>",
       3,
       "Posted by",
       Thread.current[:user]
    )
end
def started_at
  if self.start_at
    return self.start_at
  elsif (i = self.project.milestones.index(self)) > 0
    return 1.days.since(self.project.milestones.values_at(i-1).first.due_at)
  else
    return self.project.add_at
  end
end

end
